<?php

namespace app\model;

use app\BaseModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasMany;
use app\model\not_del\RatingScaleModel as NotDelRatingScaleModel;
use app\model\not_del\UserModel as NotDelUserModel;

/**
 * 任务用户答题结果
 */
class TaskUserResultModel extends BaseModel
{
    protected $name = 'task_user_result';

    /**
     * 提交测评结果验证
     * @return string[]
     */
    public function addValidate(): array
    {
        return [
            'task_id|任务ID' =>  'require',
            'task_rating_scale_id|任务量表ID' =>  'require',
            'rating_scale_id|量表ID' =>  'require',
            'mode_id|量表模板ID' =>  'require',
            'answer_role|答题角色' =>  'require',
            'question_answer|用户填写的答案' =>  'require',
            'finish_used_time|用户完成用时' =>  'require',
            'result_read_auth|结果查看权限' =>  'require',
        ];
    }

    /**
     * 关联预警因子-单个
     * @return BelongsTo
     */
    public function warningName(): BelongsTo
    {
        return $this->belongsTo('RatingScaleFactorWarningModel','warning_id')->bind([
            'warning_name' => 'name',
        ]);
    }

    /**
     * 关联用户信息
     * @return BelongsTo
     */
    public function user2(): BelongsTo
    {
        return $this->belongsTo(NotDelUserModel::class, 'uid')->bind([
            'user_name' => 'name',
            'age',
            'sex',
            'username',
            'department_id',
        ]);
    }

    /**
     * 关联量表
     * @return BelongsTo
     */
    public function ratingScale(): BelongsTo
    {
        return $this->belongsTo(NotDelRatingScaleModel::class, 'rating_scale_id')->bind([
            'rating_scale_introduce' => 'introduce',
            'rating_scale_notice' => 'notice',
            'rating_scale_type_name',
            'rating_scale_name' => 'name',
            'use_price',
            'rating_scale_cover' => 'cover',
            'previous_name',
            'mode_name'
        ]);
    }

    /**
     * 关联用户信息
     * @return BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(NotDelUserModel::class, 'uid')->bind([
            'user_name' => 'name',
            'user_avatar' => 'avatar',
            'age',
            'sex',
            'username',
            'user_number',
            'student_status',
            'department_name',
            'unit_name',
            'role_name',
            'department_id',
            'departmentAdmins'
        ]);
    }


    /**
     * 关联预警因子-单个
     * @return BelongsTo
     */
    public function RatingScaleFactorWarningModel(): BelongsTo
    {
        return $this->belongsTo('RatingScaleFactorWarningModel','warning_id')->bind([
            'warning_name' => 'name',
            'mark_id',
            'mark_count',
            'mark_color_id',
            'factor_name',
            'factor_id'
        ]);
    }

    /**
     * 关联测评因子
     * @return HasMany
     */
    public function TaskFactorScore(): HasMany
    {
        return $this->hasMany(TaskFactorScoreModel::class,'result_id');
    }

    /**
     * 关联测评因子
     * @return HasMany
     */
    public function FactorScore(): HasMany
    {
        return $this->hasMany(TaskFactorScoreModel::class,'result_id');
    }

    /**
     * 关联任务
     * @return BelongsTo
     */
    public function task(): BelongsTo
    {
        return $this->belongsTo(TaskModel::class,'task_id')->bind([
            'task_name' => 'name',
        ]);
    }

    /**
     * 关联解读人名称
     * @return BelongsTo
     */
    public function ExplainUserName(): BelongsTo
    {
        return $this->belongsTo(NotDelUserModel::class,'explain_uid')->bind([
            'explain_user_name' => 'name',
        ]);
    }

    /**
     * 关联用户名称
     * @return BelongsTo
     */
    public function UserName(): BelongsTo
    {
        return $this->belongsTo(NotDelUserModel::class,'uid')->bind([
            'user_name' => 'name',
        ]);
    }

    /**
     * 关联量表
     * @return BelongsTo
     */
    public function RatingScaleName(): BelongsTo
    {
        return $this->belongsTo(NotDelRatingScaleModel::class,'rating_scale_id')->bind([
            'rating_scale_name' => 'name',
        ]);
    }

}